luci-base: properly handle promise targets in Request.request()
authorJo-Philipp Wich <[email protected]>
Mon, 21 Feb 2022 13:59:16 +0000 (14:59 +0100)
committerJo-Philipp Wich <[email protected]>
Mon, 21 Feb 2022 14:06:41 +0000 (15:06 +0100)
commit31a27f3087412cefc5703ef106a2332af420d3f9
tree0260146ab702d1908a837c5a8c05ad087783485a
parentcc582ebfb3cb2782db841ad2a4e908d1df4046f9
luci-base: properly handle promise targets in Request.request()

Under some circumstances, ubus RPC requests may be initiated while LuCI is
still resolving the `rpcBaseURL` value. In this situation, the `target`
argument of the `request()` call will be a pending promise object which
results in an invalid URL when serialized by `expandURL()`, leading to an
`Failed to execute 'open' on 'XMLHttpRequest': Invalid URL` exception.

This commonly occured on the index status page which immediately initiates
ubus RPC calls on load to discover existing status page partials.

Solve the issue by filtering the given `target` argument through
`Promise.resolve()` before expanding the URL and initiating the actual
request.

Fixes: #3747
Signed-off-by: Jo-Philipp Wich <[email protected]>
(cherry picked from commit 5663fd596b567d53587fcc4052df3095520c08a7)
modules/luci-base/htdocs/luci-static/resources/luci.js